<?php
/**
 * 个人资料管理
 */
namespace app\admins\controller\sys;
use \app\admins\controller\Auth;

class User extends Auth{
    
    
    /**
     * 查看个人资料
     */
    public function info(){
        try{       
            $Admin = new \logic\admin\Admin($this->userId);
            $admin = $Admin->getInfo();
            $login = $Admin->getLoginList(['limit'=>2]);
            $this->assign(get_defined_vars());
            return $this->fetch();
        }catch( \think\Exception $e){
            return $this->error( $e->getMessage());
        }
    }
    
    /**
     * 修改资料
     */
    public function edit(){
        try{       
            if(request()->isPost()){
                $param = array(
                    'password'  => input('password'),
                    'confirmpwd'=> input('confirmPwd'),
                    'name'      => input('name'),
                    'mobile'    => input('mobile'),
                );
                $AdminManage = new \logic\admin\AdminManage($this->getUser());
                $result = $AdminManage->edit($this->userId,$param);
                return $this->success('修改成功','/sys/user/info');
                exit;
            }
            $Admin = new \logic\admin\Admin($this->userId);
            $admin = $Admin->getInfo();
            $this->assign(get_defined_vars());
            return $this->fetch();
        }catch( \think\Exception $e){
            return $this->error( $e->getMessage());
        }
    }
}